#include "precompiled.h"
#include "prsTest.h"
using namespace prsTest;

// TNode //////////////////////////////////////////////////////////////////////

//
void TNode::TestTNode()
{
  char *S =
  "Info                        \r\n"
  "{                           \r\n"
  "  Field                     \r\n"
  "  {                         \r\n"
  "    Name = \"name\"         \r\n"
  "    InDbTableName = \"\"    \r\n"
  "    Caption = \"caption\"   \r\n"
  "    Type = \"Ref\"          \r\n"
  "    {                       \r\n"
  "      ToFieldId = \"456\"   \r\n"
  "    }                       \r\n"
  "    Type1 = \"a\"           \r\n"
  "  }                         \r\n"
  "}                           \r\n"
  "Info1 = \"b\"               \r\n"
  ;

  svl::TString SOut;

  svl::TMem Mem; Mem.Add((BYTE*)S,lstrlen(S));
  snt::text::TContext Context; 
  Context.Text() = Mem;

  SOut = ""; for (int N = 0; N < Context.Text().CountLines(); N++)
  {
    SOut << Context.Text().GetLine(N) << "\r\n";
  }
  SOut << "\r\n";

  svl::TNodeS OutNode; OutNode.Name = "OutNode";
  prs::TNodeSRule Node(Context,OutNode);

  Context.Text() = Mem;
  OutNode.Children.Delete();

  if (!Node.Execute())
  {
    svl::TMessageModal(svl::TString("Errors") 
      << "\r\n" << Context.GetErrorsInfo());
    return;
    //svl::TString SErr; SErr.FillToLen(Context.Errors.Get(0).Col,' ');
    //SErr << "^" << Context.Errors.GetAsString();
    //SOut << SErr;
  }
  SOut << OutNode.GetAsString();
  svl::TMessageModal(SOut);
}

//
void TNode::Test()
{
  svl::TWindow MainWin;
  
  TestTNode();
}

